home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / tcomm50.zip / QBTTL.C < prev    next >
Text File  |  1989-07-31  |  25KB  |  1,101 lines

  1. /*
  2. **  QBTTL is a complete, if somewhat limited, terminal emulation
  3. **  program  designed to demonstrate the use of the LiteComm(tm)
  4. **  ToolBox.  The executable version is included so that you can
  5. **  try it out while viewing the code.  To successfully create a
  6. **  new version of QBTTL, you must have the XMODEM and WXMODEM engines
  7. **  which are provided as part of your registration package.  The
  8. **  QUICKB functionality is derived from public domain code, and adapted
  9. **  by Information Technology for use with LiteComm.
  10. **  Also note that the windowing parts of the program are based upon
  11. **  Vitamin-C by Creative Programming.  You must have this product and
  12. **  be a registrant to successfully compile a new version of QBTTL.
  13. **
  14. **  While non-registered users cannot create a new version of QBTTL, as-is
  15. **  we have provided the source as part of the distribution package to
  16. **  help you in your understanding of the way in which the LiteComm
  17. **  Communications ToolBox can be used.
  18. **
  19. **  QBTTL functions as a vidtex terminal when used in conjuction with
  20. **  CompuServe.  In addition, it will run on any communications port from
  21. **  1 thru 4, defaulting to port 2 (COM2).  To execute QBTTL on other than
  22. **  COM2, specify
  23. **    QBTTL n
  24. **  where n is a number from 1 to 4.
  25. **
  26. **  Please note also that, to send a Ctrl-C, you must use the Alt-C keys
  27. **
  28. **  Information Technology, Ltd.
  29. */
  30.  
  31. #include "litecomm.h"
  32. #include "litexm.h"
  33. #include <vcstdio.h>
  34.  
  35. #ifdef __TURBOC__
  36. #include <stdlib.h>
  37. #include <dos.h>
  38. #include <fcntl.h>
  39. #include <sys\stat.h>
  40. #include <io.h>
  41. #include <mem.h>
  42. #endif
  43.  
  44. #ifdef M_I86
  45. #include <signal.h>
  46. #include <conio.h>
  47. #include <ctype.h>
  48. #include <fcntl.h>
  49. #include <stdio.h>
  50. #include <sys\types.h>
  51. #include <sys\stat.h>
  52.  
  53. #endif
  54.  
  55. #ifdef __TURBOC__
  56. extern unsigned _stklen = 8192;
  57. #endif
  58.  
  59. #define CTRLX 0x18
  60.  
  61. #define ESC 0x1b
  62. #define ENQ 0x05
  63.  
  64. int nocbrk();
  65. void moveleft();
  66. void moveright();
  67. void moveup();
  68. void movedn();
  69. void show_modem();
  70. void simtab();
  71. void setcursorpos();
  72. void procesc();
  73. void clreos();
  74. void send(void);
  75. void recv(void);
  76. void xupload(void);
  77. void xdnload(void);
  78. void wupload(void);
  79. void wdnload(void);
  80.  
  81. /*
  82. **  Comm parameters - human-readable form
  83. */
  84. int baud = 2400;
  85. char parity = 'N';
  86. int data = 8;
  87. int stop = 1;
  88.  
  89. /*
  90. **  Comm parameters - Litecomm form
  91. */
  92. unsigned pbaud = 2400;
  93. unsigned pparity = NPARITY;
  94. unsigned pbits = BIT8;
  95. unsigned pstop = STOP1;
  96.  
  97. unsigned port = 2;
  98.  
  99. int xmode = 0;                          /* xmodem type */
  100. int yxmode = 0;                            /* use small blocks */
  101. int halfd = 0;                          /* half-duplex */
  102. int hostm = 0;                          /* host mode */
  103. int ctlc_hit = FALSE;
  104.  
  105. char MODEMSET0[] = "ATZ\r";
  106. char MODEMSET1[] = "ATT E0\r";
  107. char MODEMSET2[] = "ATC1 V0 X1 S0=1 M1\r";
  108.  
  109. COUNT mwin;                             /* for Vitamin-C */
  110. COUNT swin;
  111.  
  112. COUNT mbd;
  113. COUNT mbg;
  114. COUNT msay;
  115. COUNT mact;
  116. COUNT mnact;
  117. COUNT mtitle;
  118. COUNT sbd;
  119. COUNT sbg;
  120. COUNT ssay;
  121. COUNT sact;
  122. COUNT snact;
  123. COUNT stitle;
  124. char    strbuf[80];                   /* for sprintf usage */
  125.  
  126. void main(argc, argv)
  127. int    argc;
  128. char *argv[];
  129. {
  130.     COUNT    opt;
  131.  
  132. #ifdef M_I86
  133.     signal(SIGINT, nocbrk);               /* set Ctrl-Break handler */
  134. #endif
  135.  
  136. #ifdef __TURBOC__
  137.     ctrlbrk(nocbrk);
  138. #endif
  139.  
  140. /*
  141. **  check for a port parameter
  142. */
  143.     if (argc > 1)
  144.     {
  145.         port = atoi(argv[1]);
  146.         if ((port < 1) || (port > 4))
  147.         {
  148.             puts("Invalid Port Specified\n");
  149.             exit(4);
  150.         }
  151.     }
  152.  
  153. /*
  154. ** establish windowing environment
  155. */
  156.     vcstart(SAVESCRN);
  157.     VC_VIO = 1;
  158.     if ((mwin=wxopen(0,0,23,79,NULL,
  159.          ACTIVE+CURSOR+SCROLL+COOKED+NOADJ+CENTER, 0, 0)) == -1)
  160.         terror("mwin:Not Enough Memory");
  161.     if ((swin=wxopen(24,0,24,79,NULL,
  162.          ACTIVE+COOKED+NOADJ, 0, 0)) == -1)
  163.         terror("swin:Not Enough Memory");
  164.     wselect(mwin);
  165.  
  166. /*
  167. ** get display attributes
  168. */
  169.     wattr(mwin,&mbd, &mbg, &msay, &mact, &mnact, &mtitle, GET);
  170.     wattr(swin,&sbd, &sbg, &ssay, &sact, &snact, &stitle, GET);
  171.  
  172. /*
  173. ** set-up the comm port
  174. */
  175.     if (comm_opn(port,2400,NPARITY,BIT8,STOP1,2048,2048,FALSE) == -1)
  176.     {
  177.         urgentmsg("ERROR", "Can't open port");
  178.         abort();
  179.     }
  180.     lc_setmdm(port, (DTR | RTS));
  181.  
  182.     while (1)
  183.     {
  184.         erase();
  185.         at(0,0);
  186.         vcputs("-- MAIN MENU --\r", msay);
  187.         vcputs("T - enter Terminal mode\r", msay);
  188.         vcputs("    Alt-X leaves terminal mode\r", msay);
  189.         sprintf(strbuf, "H - toggle Host mode (now %s)\r",hostm ? "ON":"OFF");
  190.         vcputs(strbuf, msay);
  191.         sprintf(strbuf, "G - toGgle half-duplex mode (now %s)\r",halfd ? "ON":"OFF");
  192.         vcputs(strbuf, msay);
  193.         sprintf(strbuf, "C - change Comm parameters (now %d,%c,%d,%d)\r",
  194.                 baud,parity,data,stop);
  195.         vcputs(strbuf, msay);
  196.         sprintf(strbuf, "X - change Xmodem mode (now %s)\r",xmode ? "WIN":"NOR");
  197.         vcputs(strbuf, msay);
  198.         sprintf(strbuf, "Y - toggle Ymodem mode (now %s)\r",yxmode ? "ON":"OFF");
  199.         vcputs(strbuf, msay);
  200.         vcputs("S - Send a file\r", msay);
  201.         vcputs("R - Receive a file\r", msay);
  202.         vcputs("Q - Quit\r\r", msay);
  203.  
  204.         opt = getone();
  205.         opt = toupper(opt);
  206.  
  207.         switch (opt)
  208.         {
  209.             case 'T':   terminal();
  210.                         break;
  211.             case 'H':   if (hostm)
  212.                             hostm = 0;
  213.                         else
  214.                         {
  215.                             hostm = 1;
  216.                             halfd = 0;
  217.                         }
  218.                         break;
  219.             case 'G':   if (halfd)
  220.                             halfd = 0;
  221.                         else
  222.                         {
  223.                             halfd = 1;
  224.                             hostm = 0;
  225.                         }
  226.                         break;
  227.             case 'X':   if (xmode)
  228.                             xmode = 0;
  229.                         else
  230.                             xmode = 1;
  231.                         break;
  232.             case 'Y':   if (yxmode)
  233.                         {
  234.                             ymodem = FALSE;
  235.                             yxmode = 0;
  236.                         }
  237.                         else
  238.                         {
  239.                             yxmode = 1;
  240.                             ymodem = TRUE;
  241.                         }
  242.                         break;
  243.             case 'S':   send();
  244.                         break;
  245.             case 'R':   recv();
  246.                         break;
  247.             case 'C':   chgcomm();
  248.                         break;
  249.         }
  250.         if (opt == 'Q')
  251.             break;                      /* shut down time */
  252.     }                                   /* while (1) */
  253.  
  254.     comm_close(port,FALSE);
  255.     vcend(CLOSE);
  256.     exit(0);
  257. }                                       /* main */
  258.  
  259. int nocbrk()
  260. {
  261. #ifdef M_I86
  262.     signal(SIGINT, SIG_IGN);             /* set Ctrl-Break handler */
  263. #endif
  264.     ctlc_hit = TRUE;
  265.     _abort_flag = TRUE;
  266. #ifdef M_I86
  267.     signal(SIGINT, nocbrk);             /* set Ctrl-Break handler */
  268. #endif
  269.     return(TRUE);
  270. }
  271.  
  272. terminal()
  273. {
  274.     COUNT ch;
  275.     COUNT row, col;
  276.     COUNT twin;
  277.  
  278.     erase();
  279.     lc_xoff(port,TRUE);
  280.  
  281.     while (1)
  282.     {
  283.         if ((ch = lc_get(port)) != -1)
  284.             switch (ch & 0x7f)
  285.             {
  286.                 case 0x08:             /* BS */
  287.                     moveleft();
  288.                     vcputc(' ', msay);
  289.                     moveleft();
  290.                     break;
  291.                 case '\t':                /* HT */
  292.                     simtab();
  293.                     break;
  294.                 case '\r':              /* CR */
  295.                     wcurspos(mwin, &row, &col);
  296.                     at(row,0);
  297.                     break;
  298.                 case DLE:
  299.                     twin=wxopen(6,20,13,60,"TRANSFER A FILE",
  300.                         BORDER+BD1+ACTIVE+CURSOR+SCROLL+COOKED+NOADJ+CENTER, 0, 0);
  301.                     wselect(twin);
  302.                     bp_DLE();
  303.                     wclose(twin);
  304.                     wselect(mwin);
  305.                     break;
  306.                 case ENQ:
  307.                     bp_ENQ();
  308.                     break;
  309.                 case ESC:
  310.                     procesc();
  311.                     break;
  312.                 default:
  313.                     if (pparity != NPARITY)
  314.                         ch &= 0x7f;                /* strip parity */
  315.                     vcputc(ch, msay);
  316.                     if (hostm)
  317.                     {
  318.                         lc_put(port,ch);            /* echo back */
  319.                         if (ch == '\r')             /* was it return */
  320.                         {
  321.                             lc_put(port,'\n');      /* echo lf as well */
  322.                             vcputc('\n', msay);
  323.                         }
  324.                     }
  325.             }
  326.         show_modem (lc_mstat(port));
  327.  
  328.         if (keyrdy())                       /* anything typed ? */
  329.         {
  330.             ch = getone();                  /* get input */
  331.             if (ch == ALT_X)
  332.                 return(0);
  333.             if (ch == ALT_C)
  334.                 ch = 0x03;
  335.             lc_put(port,ch);                /* xmit the char */
  336.             if (hostm || halfd)             /* local echo needed ? */
  337.             {
  338.                 vcputc(ch, msay);
  339.                 if (ch == '\r')             /* was it CR */
  340.                 {
  341.                     vcputc('\n', msay);     /* add LF */
  342.                     if (hostm)
  343.                         lc_put(port, '\n'); /* and send LF in host mode */
  344.                 }
  345.             }
  346.         }
  347.     }                                       /* while */
  348. }
  349.  
  350. void procesc()
  351. {
  352.     int ch;
  353.  
  354.  
  355.     ch = lc_getw(port);                    /* wait for actual comm